/**
 * Copyright 2016-2018 mobaas.com
 */
package com.mobaas.devops.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mobaas.devops.PageList;
import com.mobaas.devops.dao.ErrorLogDao;
import com.mobaas.devops.model.ErrorLog;
import com.mobaas.devops.service.ErrorLogService;

import java.util.Calendar;
import java.util.Date;

/**
 * 
 * @author billy zhang
 * 
 */
@Service
public class ErrorLogServiceImpl implements ErrorLogService {

    @Autowired
    private ErrorLogDao errlogMapper;
    
    @Override
    public PageList<ErrorLog> selectErrorLogList(Date beginTime, Date endTime, int pageNum, int pageSize) {
    		PageList<ErrorLog> plist= new PageList<>();
        plist.setPageSize(pageSize);
        plist.setPageNo(pageNum);
        if (null != endTime) {
            // 为截止日期添加上23.59.59
            Calendar cal = Calendar.getInstance();
            cal.setTime(endTime);
            cal.add(Calendar.HOUR_OF_DAY, 23);// 24小时制
            cal.add(Calendar.MINUTE, 59);
            cal.add(Calendar.SECOND, 59);
            endTime = cal.getTime();
        }
        long currentTime = System.currentTimeMillis();
        plist.setTotal(errlogMapper.selectErrorLogCount(beginTime,endTime));
        if(plist.getTotal()>0){
            int offset = (pageNum - 1) * pageSize;
            plist.setList(errlogMapper.selectErrorLogList(beginTime, endTime, offset, pageSize));
        }
        
        return plist;
    }

    @Override
    public ErrorLog selectErrorLogById(int id) {
        return errlogMapper.selectErrorLogById(id);
    }

	@Override
	public void insertErrorLog(ErrorLog plog) {
		// TODO Auto-generated method stub
		
	}
}
